package com.wms.controller;

import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.entity.Store;
import com.wms.service.StoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@Api(tags = "仓库管理")
@RestController
public class StoreController {

    @Autowired
    StoreService storeService;

    @ApiOperation("增加仓库")
    @PostMapping("addStore")
    public ResultBean addStore(@Valid @RequestBody Store store){
        System.out.println("接收的fuId: " + store.getFuId());
        int n=storeService.addStore(store);
        return R.success("添加仓库",n);
    }

    @ApiOperation("查询所有仓库名")
    @GetMapping("/chaCK")
    public ResultBean chaCk(){
        List<Map<String,Map>> list=storeService.chaCk();
        return R.success("查询所有仓库名",list);
    }

    @ApiOperation("查询所有温区")
    @GetMapping("/chaWq")
    public ResultBean chaWq(){
        List<Map<String,Map>> list=storeService.chaWq();
        return R.success("查询所有温区",list);
    }


    @ApiOperation("仓库、库区多级列表1.0")
    @GetMapping("/ckList")
    public ResultBean ckList(){
        List<Map<String, Object>> list=storeService.ckList();
        return R.success("多级目录查询",list);
    }

    @ApiOperation("仓库  树级列表2.0")
    @GetMapping("/ckTree")
    public ResultBean getStoreTree() {
        List<Map<String, Object>> tree = storeService.getStoreTree();
        return R.success("仓库层级结构", tree);
    }

    @ApiOperation("仓库 树级列表3.0（废弃）")
    @GetMapping("/ckTree3")
    public ResultBean treeCK() {
        List<Store> list=storeService.getAllStores();
        List<Store> tree=storeService.buildTree(list,0);
        return R.success("获取仓库树形结构成功", tree);
    }



    @ApiOperation("仓库删除")
    @DeleteMapping("/deleCk")
    @ApiImplicitParam(name = "id",value = "删除的仓库id",required = true,dataType = "int")
    public ResultBean deleCkById(int id){
        int n=storeService.deleCkById(id);
        return R.success("删除仓库",n);
    }




    @ApiOperation("无限映射4.0")
    @GetMapping("/WXtree")
    public ResultBean WXTree() {
        List<Store> list=storeService.WXTree();
        return R.success("返回树状结构",list);
    }
}
